﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.quest.Display.QuestManager {
    import flash.display.*;
    import org.aswing.*;
    import Classes.*;
    import org.aswing.geom.*;
    import Display.*;
    import flash.text.*;
    import org.aswing.event.*;
    import Modules.guide.ui.*;
    import org.aswing.ext.*;
    import Display.aswingui.*;
    import Display.hud.*;

    public class QuestManagerUI extends JPanel {

        public static const NUM_ROWS:int = 4;
        public static const NUM_COLUMNS:int = 5;
        public static const TOP_INSET_HEIGHT:int = 10;
        public static const RIGHT_INSET_WIDTH:int = 10;

        protected var m_questManagerView:QuestManagerView;
        protected var m_centerPanelContainer:JPanel;
        protected var m_centerPanel:JPanel;
        protected var m_titlePanel:JPanel;
        protected var m_hintPanel:JPanel;
        protected var m_bgAsset:DisplayObject;
        protected var m_closeButton:JButton;
        protected var m_tool_tip:QuestManagerToolTip;
        protected var m_model:VectorListModel;
        protected var m_gridList:GridList;
        protected var m_scrollPane:JScrollPane;
        protected var m_arrow:GuideArrow;

        public function QuestManagerUI(_arg1:LayoutManager=null){
            super(new SoftBoxLayout(SoftBoxLayout.X_AXIS, 5, SoftBoxLayout.LEFT));
            this.setPreferredSize(new IntDimension(((QuestManagerView.QUEST_MANAGER_WIDTH + 20) + QuestManagerView.QUEST_MANAGER_TOOLTIP_WIDTH), (QuestManagerView.QUEST_MANAGER_HEIGHT + 80)));
            this.makeGridList();
        }
        public function init(_arg1:QuestManagerView):void{
            this.m_questManagerView = _arg1;
            this.m_tool_tip = new QuestManagerToolTip();
            this.m_centerPanelContainer = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
            this.makeTitlePanel();
            this.makeCenterPanel();
            this.makeHintPanel();
            this.m_centerPanelContainer.append(this.m_titlePanel);
            this.m_centerPanelContainer.append(ASwingHelper.verticalStrut(-12));
            this.m_centerPanelContainer.append(this.m_centerPanel);
            this.m_centerPanelContainer.append(ASwingHelper.verticalStrut(2));
            this.m_centerPanelContainer.append(this.m_hintPanel);
            this.append(this.m_centerPanelContainer);
            this.append(this.m_tool_tip);
            this.m_tool_tip.visible = false;
            this.makeBackground();
            ASwingHelper.prepare(this);
        }
        protected function makeTitlePanel():void{
            this.m_titlePanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            this.m_titlePanel.setPreferredHeight(40);
            var _local1:String = ZLoc.t("Quest", "quest_manager_title");
            var _local2:JTextField = ASwingHelper.makeTextField(_local1, EmbeddedArt.TITLE_FONT, 16, EmbeddedArt.whiteTextColor);
            var _local3:TextFormat = new TextFormat();
            _local3.align = TextFormatAlign.CENTER;
            _local3.size = 28;
            TextFieldUtil.formatSmallCaps(_local2.getTextField(), _local3);
            _local2.setPreferredWidth(QuestManagerView.QUEST_MANAGER_WIDTH);
            this.m_titlePanel.append(_local2);
        }
        protected function makeHintPanel():void{
            this.m_hintPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            this.m_hintPanel.setPreferredHeight(48);
            var _local1:String = ZLoc.t("Quest", "quest_manager_hint");
            var _local2:AssetPane = ASwingHelper.makeMultilineText(_local1, QuestManagerView.QUEST_MANAGER_WIDTH, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, TextFormatAlign.LEFT, 16, EmbeddedArt.whiteTextColor);
            this.m_hintPanel.append(_local2);
            _local2.getAsset().height = 44;
        }
        protected function makeBackground():void{
            this.m_bgAsset = (new (QuestManagerView.assetDict["questManagerBG"])() as DisplayObject);
            var _local1:MarginBackground = new MarginBackground(this.m_bgAsset, new Insets(TOP_INSET_HEIGHT, 0, 0, RIGHT_INSET_WIDTH));
            this.m_centerPanel.setBackgroundDecorator(_local1);
            this.m_centerPanel.setPreferredSize(new IntDimension(QuestManagerView.QUEST_MANAGER_WIDTH, QuestManagerView.QUEST_MANAGER_HEIGHT));
        }
        protected function makeCenterPanel():void{
            this.m_centerPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP, -5);
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.RIGHT);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            this.m_closeButton = ASwingHelper.makeMarketCloseButton();
            this.m_closeButton.addActionListener(this.closeQuestManager, 0, true);
            _local2.append(this.m_closeButton);
            ASwingHelper.prepare(_local2);
            _local1.append(_local2);
            ASwingHelper.prepare(_local1);
            var _local3:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            _local3.append(this.m_scrollPane);
            ASwingHelper.prepare(_local3);
            this.m_centerPanel.append(_local1);
            this.m_centerPanel.append(_local3);
            ASwingHelper.prepare(this.m_centerPanel);
        }
        protected function makeGridList():void{
            this.m_model = new VectorListModel();
            this.m_gridList = new GridList(this.m_model, new QuestManagerCellFactory(), NUM_COLUMNS, NUM_ROWS);
            this.m_gridList.setHolderLayout(new GridListHorizontalLayout(NUM_ROWS, NUM_COLUMNS, 0, 0));
            this.m_gridList.setPreferredSize(new IntDimension((NUM_COLUMNS * QuestManagerCell.CELL_WIDTH), (NUM_ROWS * QuestManagerCell.CELL_HEIGHT)));
            this.m_gridList.setMinimumSize(new IntDimension((NUM_COLUMNS * QuestManagerCell.CELL_WIDTH), (NUM_ROWS * QuestManagerCell.CELL_HEIGHT)));
            this.m_gridList.setMaximumSize(new IntDimension((NUM_COLUMNS * QuestManagerCell.CELL_WIDTH), (NUM_ROWS * QuestManagerCell.CELL_HEIGHT)));
            this.m_scrollPane = new JScrollPane(this.m_gridList, JScrollPane.SCROLLBAR_NEVER, JScrollPane.SCROLLBAR_NEVER);
        }
        protected function closeQuestManager(_arg1:AWEvent):void{
            this.m_questManagerView.close();
        }
        public function fixLayout():Boolean{
            var _local1:AssetPane = (this.m_hintPanel.getComponent(0) as AssetPane);
            if (((!((_local1 == null))) && ((_local1.getAsset().height < 20)))){
                _local1.getAsset().height = 40;
                return (true);
            };
            return (false);
        }
        public function addIcon(_arg1:QuestManagerSprite):void{
            var _local2:String;
            if (this.m_model.isEmpty()){
                this.m_model.append(_arg1);
                this.m_gridList.setModel(this.m_model);
            } else {
                if (!this.iconExists(_arg1.name)){
                    this.m_model.append(_arg1);
                };
            };
            Global.hud.setHUDComponentVisible(HUD.COMP_QUEST_MANAGER_ICON, true);
            if (Global.player.getSeenFlag("SeenQuestManager") == false){
                if (Global.player.getLastActivationTime("SeenQuestManager") < 0){
                    _local2 = Global.getAssetURL("assets/hud/tutorialArrow.swf");
                    this.m_arrow = Global.guide.displayArrow(_local2, 160, 400, 0, 0, GuideArrow.ARROW_LEFT, true);
                };
                Global.player.setSeenFlag("SeenQuestManager");
            };
        }
        public function removeIcon(_arg1:QuestManagerSprite, _arg2:Boolean=true):QuestManagerSprite{
            var _local3:QuestManagerSprite = this.m_model.remove(_arg1);
            if (((_arg2) && ((this.numIcons <= 0)))){
                Global.hud.setHUDComponentVisible(HUD.COMP_QUEST_MANAGER_ICON, false);
                if (this.m_arrow){
                    Global.guide.removeArrows();
                    this.m_arrow = null;
                };
            };
            return (_local3);
        }
        public function removeIconByName(_arg1:String):QuestManagerSprite{
            var _local3:QuestManagerSprite;
            var _local2:int;
            while (_local2 < this.m_model.size()) {
                _local3 = this.m_model.getElementAt(_local2);
                if (((_local3) && ((_local3.name == _arg1)))){
                    return (this.removeIcon(_local3));
                };
                _local2++;
            };
            return (null);
        }
        public function iconExists(_arg1:String):Boolean{
            var _local3:QuestManagerSprite;
            var _local2:int;
            while (_local2 < this.m_model.size()) {
                _local3 = this.m_model.getElementAt(_local2);
                if (((_local3) && ((_local3.name == _arg1)))){
                    return (true);
                };
                _local2++;
            };
            return (false);
        }
        public function get numIcons():int{
            return (this.m_model.size());
        }
        public function popFirstQuestIcon():QuestManagerSprite{
            var _local1:QuestManagerSprite = this.m_model.first();
            return (this.removeIcon(_local1));
        }
        public function get model():VectorListModel{
            return (this.m_model);
        }
        public function get questToolTip():QuestManagerToolTip{
            return (this.m_tool_tip);
        }
        public function get titlePanel():JPanel{
            return (this.m_titlePanel);
        }
        public function get guideArrow():GuideArrow{
            return (this.m_arrow);
        }
        public function set guideArrow(_arg1:GuideArrow):void{
            this.m_arrow = _arg1;
        }

    }
}//package Modules.quest.Display.QuestManager 
